import time
import urllib.request
from bs4 import BeautifulSoup
import json
import re
import math
import sys

class Processor:
    #从这里开始写选择器
    soup = BeautifulSoup(task.getHtml(), "lxml")
    content_list = soup.select('div[class="content"]')
    
    data = {}

    for item in content_list:
        data['url'] = item.xpath('')
        data['data']['url'] =

        detail_html = urllib.request.urlopen(data['url']).read()
        detail_soup = BeautifulSoup(detail_html, "lxml")
        data['data']['content'] = detail_soup.xpath('')

        data['data']['issue_time'] =
        data['data']['create_time'] =
        data['data']['update_time'] =
        data['data']['twitter_name'] =

        #处理时间戳
        time_str = data['data']['issue_time']

        # 年
        year = time_str[-4:]

        # 月
        month_pattern = r'\w{3,}'
        month = re.search(month_pattern, time_str).group(0)
        month = month.replace("Jan", "1")
        month = month.replace("Feb", "2")
        month = month.replace("Mar", "3")
        month = month.replace("Apr", "4")
        month = month.replace("May", "5")
        month = month.replace("Jun", "6")
        month = month.replace("Jul", "7")
        month = month.replace("Aug", "8")
        month = month.replace("Sep", "9")
        month = month.replace("Oct", "10")
        month = month.replace("Nov", "11")
        month = month.replace("Dec", "12")

        # 日
        date_pattern = r'- \d{1,2} '
        date = re.search(date_pattern, time_str).group(0)
        date = date.replace(" ", "")
        date = date.replace("-", "")

        # 小时
        hour_pattern = r'\d{1,2}:'
        hour = re.search(hour_pattern, time_str).group(0)
        hour = hour.replace(":", "")

        # 分钟
        minute_pattern = r':\d{1,2} '
        minute = re.search(minute_pattern, time_str).group(0)
        minute = minute.replace(" ", "")
        minute = minute.replace(":", "")

        # 秒
        second = '00'

        time_stamp = ''
        dt = year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second

        timeArray = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
        time_stamp = math.floor(time.mktime(timeArray))

        data['data']['issue_time'] = time_stamp


        #解析完毕，返回到存储队列；url返回到selector
        queue.put(data)

        #存在多个processor，可以通过dict函数生成嵌套字典
        nested_data = dict(data)
        print(nested_data)